package com.threeti.mecool.core.infrastructure.persistence.project;

import com.threeti.mecool.core.domain.model.project.Project;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

public interface ProjectRepository extends JpaRepository<Project, Long>, JpaSpecificationExecutor<Project> {
  /** 取得特定员工参与的所有项目 */
  @Deprecated
  @Query("select distinct p from Project p inner join fetch p.participatedEmployees e where e.empId = ?1")
  List<Project> findByParticipatedEmployeeId(Long empId);

  /** 取得特定项目，预抓取出productsNeedToBeCollected */
  @Deprecated
  @Query("select p from Project p left join fetch p.productsNeedToBeCollected ppc where p.id= ?1")
  Project findWithProductsNeedToBeCollected(Long projectId);

  /** 根据项目名取得特定项目 */
  Project findByName(String projName);

  /** 根据项目编号取得特定项目 */
  Project findByCode(String code);

  @Query("select distinct(p.managerEmpId) from Project p where p.orgCode IN :orgCodes")
  List<Long> findByOrgCodeIn(@Param("orgCodes") List<String> orgCodes);

  List<Project> findByIdIn(List<Long> idList);

}
